﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Worktool.CODE_Chris.SQL_DATA;

namespace Worktool.CODE_Chris.DataSourceHelpers
{
    public class GeneralHelper
    {
        private Color[] color = new Color[6];
        private SQL sql;

        string[] formats = {"dd.MM.yyyy","dd.MM.yyyy hh:mm:ss"};

        public GeneralHelper()
        {
            init();
        }

        private void init()
        {
            sql = new SQL();

            setColors();
        }

        public Boolean IsDateExact(String date)
        {
            DateTime dt;
            return DateTime.TryParseExact(date, formats,new CultureInfo("de-DE"), DateTimeStyles.None, out dt);
        }

        //OLD
        //public Boolean IsDate(String date)
        //{
        //    DateTime dt;
        //    return DateTime.TryParse(date, out dt);
        //}

        private void setColors()
        {
            //Blau
            color[0] = Color.FromArgb(192, 192, 255);

            //Orange
            color[1] = Color.FromArgb(255, 224, 192);

            //Grün
            color[2] = Color.FromArgb(192, 255, 192);

            //Rosa
            color[3] = Color.FromArgb(255, 192, 255);

            //Türkis
            color[4] = Color.FromArgb(192, 255, 255);

            //Rot
            color[5] = Color.FromArgb(254, 231, 231);
        }

        public Color[] getColors()
        {
            return color;
        }

        public DataGridViewComboBoxColumn createComboBoxColumn(String name)
        {
            DataGridViewComboBoxColumn column =
                new DataGridViewComboBoxColumn();
            {
                column.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                column.DataPropertyName = name;
                column.HeaderText = name;
                column.MaxDropDownItems = 3;
                column.FlatStyle = FlatStyle.Flat;
            }
            return column;
        }

        public DataTable populate(string sqlCommand)
        {
            try
            {
                SqlDataAdapter adapter = new SqlDataAdapter(sqlCommand, Login.connection);

                DataTable table = new DataTable();
                table.Locale = System.Globalization.CultureInfo.InvariantCulture;
                adapter.Fill(table);

                return table;
            }
            catch (Exception e)
            {
                sql.log("FEHLER", e, this.ToString() + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name);
                return null;
            }
        }
    }


}
